- /* snmcopyv.cpp by K.Tsuru */
- // function ID = 104
- /****************************************************************
- SNumber class
- It copies various values, FigBlock figure,etc.
- If cs = COPY, it sets figure = a.figure only.This is used in the copy
- constructor of te derived class.
- If cs = SUBS, it allocates memory or adjusts the size of figure.
- This is used in the substitution operators.
- *****************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- #ifndef NDEBUG
- static const char* func = "CopyValue";
- #endif
-
- void SNumber::CopyValue(const SNumber& a, int cs)
- {
- if(this == &a) return; //For a = a.
-
- aHead = a.aHead; aTail = a.aTail; type = a.type;
-
- // Called by copy constructor.
- if(cs == COPY){
- figure = a.figure;
- #ifndef NDEBUG
- assert(figure.Error() == figure.NORMAL);
- #endif
- sign = a.sign;
- return;
- }
- if(a.sign == ZERO){ // a = 0; It may be able to minimize the size.
- //If Sign() is used UNDEC_VALUE error occures.
- //Do not use figure.size(minArraySize,0); It may be cutDown == DISABLE.
- SetZero(); return;
- }
-
- //It prohibits to substitute an unsubstantial object for a substantial one.
- if( (a.figure.size() == 0) || (a.sign == UNDECIDED) ){
- if(figure.size() > 0) SetError(UNDEC_VALUE, "", 104);
- return; // a.figure.size() = figure.size() = 0 is OK.
- }
- // sign = a.sign; // Execute in last line.
-
- /********************************************************
- When CutDown() == DISABLE, do not reduce the size of this.
- See Lpow() function for example.
- *********************************************************/
- uint alc_sz;
-
- if(CutDown() == DISABLE) alc_sz = max(a.figure.size(), figure.size());
- else alc_sz = a.aHead +1;
- valloc(alc_sz, -1); //It does not copy and allocates the memory. sign = UNDECIDED;
- uint max_sz = SNMaxSize(type), n_copy;
-
- if(type & REAL){ // real type
- n_copy = min(figure.size(), a.aHead+1);
- //It considers the substitution of longer number e.g. E()
- //after reducing the number of effective figures.
- if(n_copy > max_sz) n_copy = max_sz;
- } else n_copy = a.aHead + 1; // integer type
-
- //It copies the lower part of a.
- memcpy(figure.Elements(), a.ReadFigures() , n_copy*sizeof(fType) );
- figure.clear(n_copy); //It fills the upper part with zeros. figure[i]=0 for i>aHead
- sign = a.sign; // sign : change UNDECIDED to a.sign
-
- if(aHead >= max_sz){//The number of effective figures was reduced by calling SetEffFig().
- CheckArray(-104);//It rarely occures.
- }
- //check errors
- #ifndef NDEBUG
- int sc = (sign == UNDECIDED) || (sign == ZERO) || (sign == PLUS) || (sign == MINUS);
- if(!sc){
- SetError(FATAL, func, (int)sign);
- }
- if(figure.Error() != figure.NORMAL) SetError(FATAL, func, 104);
- if( aHead >= figure.size() ) SetError(FATAL, func, (int)aHead);
- if( aTail > aHead ){
- SetError(FATAL, func, (int)aTail);
- }
- #endif
- }
snmcopyv.cpp : last modifiled at 2017/03/13 14:32:01(2,935 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).